﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PatternChainResp
{
    class Program
    {
        static void Main(string[] args)
        {
            //实现所有处理单元
            Handler lowLeader = new LowLeader();
            Handler midLeader = new MidLeader();
            Handler bossLeader = new BossLeader();

            //将处理单元成链
            lowLeader.SetNextHandler(midLeader);
            midLeader.SetNextHandler(bossLeader);
             
            lowLeader.Process(212);

            Console.ReadKey();

        }
    }

    //抽象的处理单元
    abstract class Handler
    {
        protected Handler nextHandler;
        public void SetNextHandler(Handler _nextHandler)
        {
            nextHandler = _nextHandler;
        } 
        public abstract void Process(int info); 
    }



    class LowLeader : Handler
    {
        public override void Process(int info)
        {
            if (info >= 0 && info < 10)
            {
                Console.WriteLine("low process");
            }
            else 
            {
                nextHandler.Process(info);
            } 
        }
    }


    class MidLeader : Handler
    {
        public override void Process(int info)
        {
            if (info >= 10 && info < 20)
            {
                Console.WriteLine("mid process");
            }
            else
            {
                nextHandler.Process(info);
            }
        }
    }


    class BossLeader : Handler
    {
        public override void Process(int info)
        {
            if (info >= 20  )
            {
                Console.WriteLine("boss process");
            }
           
        }
    }
     

}
